#include "svgsquareelement.h"


#include "colortransformer.h"

SvgSquareElement::SvgSquareElement(SvgNode *parent)
	:SvgRectElement(parent)
{
}


QDomElement SvgSquareElement::toXmlImpl(QDomElement &parent) const{
	QDomElement curr = SvgRectElement::toXmlImpl(parent);

	curr.setAttribute("square", "1");

	return curr;
}



void SvgSquareElement::onResize(QRectF rect){

	QRectF rectNew = rect;
	//fix
	rectNew = QRectF(rectNew.x() + m_strokeWidth / 2.f, rectNew.y() + m_strokeWidth / 2.f, rectNew.width() - m_strokeWidth, rectNew.height() - m_strokeWidth);
	QRectF rectOld = QRectF(m_frame.x() + m_strokeWidth / 2.f, m_frame.y() + m_strokeWidth / 2.f, m_frame.width() - m_strokeWidth, m_frame.height() - m_strokeWidth);

	QPointF fixedPoint;
	if (this->resizeFixedPoint(rectNew, rectOld, fixedPoint))
	{
		qreal maxmin = 0;
		if (rectNew.width()*rectNew.height() > rectOld.width()*rectOld.height())
		{
			maxmin = rectNew.width() > rectNew.height() ? rectNew.width() : rectNew.height();
		}
		else
		{
			maxmin = rectNew.width() < rectNew.height() ? rectNew.width() : rectNew.height();
		}

		m_width = maxmin;
		m_height = maxmin;
		m_x = rect.left();
		m_y = rect.top();

		updateFrame();
		updateShape();
	}
	SvgNode::onResize(rect);
}


